/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustCar;
import com.sasis.dao.FlightAdjustCarDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustCarDaoiBatis extends BaseDaoiBATIS implements FlightAdjustCarDao {

    /**
     * @see com.sasis.dao.FlightAdjustCarDao#getFlightAdjustCars(com.sasis.model.FlightAdjustCar)
     */
    public List getFlightAdjustCars(final FlightAdjustCar flightAdjustCar) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustCars", flightAdjustCar);
    }

    /**
     * @see com.sasis.dao.FlightAdjustCarDao#getFlightAdjustCar(Integer id)
     */
    public FlightAdjustCar getFlightAdjustCar(Integer id) {
        FlightAdjustCar flightAdjustCar = (FlightAdjustCar) getSqlMapClientTemplate().queryForObject("getFlightAdjustCar", id);

        //if (flightAdjustCar == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustCar.class, id);
        //}

        return flightAdjustCar;
    }

    /**
     * @see com.sasis.dao.FlightAdjustCarDao#saveFlightAdjustCar(FlightAdjustCar flightAdjustCar)
     */    
    public int saveFlightAdjustCar(final FlightAdjustCar flightAdjustCar) {
        Integer id = flightAdjustCar.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustCar", flightAdjustCar);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustCar", flightAdjustCar);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustCar.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustCarDao#removeFlightAdjustCar(Integer id)
     */
    public void removeFlightAdjustCar(FlightAdjustCar flightAdjustCar) {
        getSqlMapClientTemplate().update("deleteFlightAdjustCar",  flightAdjustCar);
    }
}
